package com.studio5704website.infrastructure.repository;

import com.studio5704website.core.security.UrlPermission;
import com.studio5704website.infrastructure.mapper.UrlPermissionMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author Gao
 * 从数据库里查找url-permission
 */
@Repository
public class MyBatisUrlPermissionRepository implements UrlPermission {
    @Autowired
    private UrlPermissionMapper urlPermission;

    @Override
    public Map<String, String> getUrlPermission() {
        List<Map<String, String>> urlPermissionTable = urlPermission.getUrlPermissionTable();
        Map<String, String> urlPermission = new HashMap<>();
        urlPermissionTable.forEach(id -> {
            urlPermission.put(id.get("URL"), id.get("PERMISSION"));
        });
        return urlPermission;
    }
}
